;(function($){

	var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent);

	$.fn.loading = {
		
		defaults : {
			message : 'Carregando...',
			imgSrc : '/html/js/images/jquery.loading.gif',
			fadeTime : 600,
			position : 'fixed',
			loadingDiv : null
		},
		
		_load : function(o){
			
			var div, o = $.extend({}, this.defaults, o);
			
			if(!o.loadingDiv){
			
				div = $('<div class="loading bealty"></div>')
					.css('position', o.position)
					.append('<div class="inner">'+o.message+'</div>')
					.append('<div><img src="'+o.imgSrc+'" alt="'+o.message+'" /></div>');
				
			}
			
			if (ie6) {
				div.get(0).style.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');
				div.get(0).style.marginTop = 0;
			}
			
			div.appendTo('body').fadeIn(o.fadeTime);
						
		},
		
		_unload : function(){
			
			var o = $.extend({}, this.defaults, o);
			
			$('div.loading', 'body').fadeOut(o.fadeTime, function(){$(this).remove()});
		}
	}
	
	$.fn.showLoading = function(opt){
		
		return this.each(
			function(){
				
				if(!opt) opt = {};
					
				opt["loadingDiv"] = this;
				
				$.showLoading(opt);
			});
	};
	
	$.extend({
	
		showLoading : function(opt){
			
			return	$.fn.loading._load(opt);
		},
		
		hideLoading : function(opt){
			
			return	$.fn.loading._unload(opt);
		}	
	});
	
})(jQuery);
